package com.cheng.controller;

import com.cheng.common.results.DataRslt;
import com.cheng.data.vo.BorrowInfoVO;
import com.cheng.data.vo.ReqPageInfoVO;
import com.cheng.data.vo.RespPageInfoVO;
import com.cheng.operation.BorrowOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author: ChengJW
 * @date: 2021/12/20 17:30
 * @version: 1.0
 * @description: 档案借阅处理类
 */
@Controller
public class ReadController extends BaseController{

    private final static Logger log = LoggerFactory.getLogger(ReadController.class);

    @Autowired
    private BorrowOperation borrowOperation;

    @RequestMapping("/archivesRead/read")
    public String archivesRead(){
        return "archivesRead";
    }

    @RequestMapping("/read/archivesReadIn")
    public String archivesReadIn(){
        return "archivesReadIn";
    }

    @RequestMapping("/read/archivesReadOut")
    public String archivesReadOut(){
        return "archivesReadOut";
    }

    @RequestMapping("/archivesReadOut/readInfo")
    public String readInfo(ModelMap map){
        map.put("urRealNm",getUrRealNm());
        return "readInfo";
    }

    /**
    * @author: ChengJW
    * @params:
    * @return:
    * @date: 2021/12/20
    * @description: 新增借阅信息
    */
    @RequestMapping("/archivesReadOut/readInfo/addReadInfo")
    @ResponseBody
    public DataRslt addReadInfo(BorrowInfoVO borrowInfoVO){
        borrowInfoVO.setBwNm(getUrNm());
        borrowOperation.insertBorrowInfo(borrowInfoVO);
        return success();
    }

    /**
    * @author: ChengJW
    * @params: [pageInfoVO]
    * @return: com.cheng.common.results.DataRslt
    * @date: 2021/12/20
    * @description: 查询待归还的企业信息
    */
    @RequestMapping("/archivesReadIn/queryBorrowInfoList")
    @ResponseBody
    public DataRslt queryBorrowInfoList(ReqPageInfoVO pageInfoVO){
        pageInfoVO.setUserCode(getUrCode());
        RespPageInfoVO respPageInfoVO = borrowOperation.queryBorrowInfoList(pageInfoVO);
        return tabSuccess(respPageInfoVO);
    }

    @RequestMapping("/archivesReadIn/readIn")
    @ResponseBody
    public DataRslt readIn(@RequestParam("bwIdList")List<String> bwBussIdList){
        borrowOperation.updateBorrowInfo(bwBussIdList,getUrNm());
        return success();
    }
}
